﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using VDataAdapter.PriceServerAdapter;

namespace VDataAdapter.EventManagement
{
    class EventToHandlerPasser
    {

        public static void PassEvent(Event e, IPriceServerEventHandler handler)
        {
            if(e is FirstTimeEvent)                
            {
                var target = (FirstTimeEvent)e;
                handler.GetFirstTime(target.Baseprices, target.Top3Prices);
            }

            if (e is Top3PricesEvent)
            {
                var target = (Top3PricesEvent)e;
                handler.Top3PricesStock_Changed(target.Top3Prices);
            }

            if (e is TransactionsEvent)
            {
                var target = (TransactionsEvent)e;
                handler.Transactions_Changed(target.TransactionsList, target.CountNumber, target.TotalCountNumber);                    
            }

            if (e is MarketInfosEvent)
            {
                var target = (MarketInfosEvent)e;
                handler.MarketInfo_Changed(target.MarketInfosList);
            }
                    
            if (e is PtTopPricesChangedEvent)
            {
                var target = (PtTopPricesChangedEvent)e;
                handler.PutThroughTopPrices_Changed(target.PtTopPricesList);
            }

            if (e is PtTransactionsChangedEvent)
            {
                var target = (PtTransactionsChangedEvent)e;
                handler.PutThroughTransactions_Changed(target.Transactions);
            }

            throw new TypeUnloadedException("Unknown type of event");
        }

        public static void PassEvent(FirstTimeEvent e, IPriceServerEventHandler handler)
        {
            handler.GetFirstTime(e.Baseprices, e.Top3Prices);
        }

        public static void PassEvent(Top3PricesEvent e, IPriceServerEventHandler handler)
        {
            handler.Top3PricesStock_Changed(e.Top3Prices);
        }

        public static void PassEvent(TransactionsEvent e, IPriceServerEventHandler handler)
        {
            handler.Transactions_Changed(e.TransactionsList, e.CountNumber, e.TotalCountNumber);
        }

        public static void PassEvent(MarketInfosEvent e, IPriceServerEventHandler handler)
        {
            handler.MarketInfo_Changed(e.MarketInfosList);
        }

        public static void PassEvent(PtTopPricesChangedEvent e, IPriceServerEventHandler handler)
        {
            handler.PutThroughTopPrices_Changed(e.PtTopPricesList);
        }

        public static void PassEvent(PtTransactionsChangedEvent e, IPriceServerEventHandler handler)
        {
            handler.PutThroughTransactions_Changed(e.Transactions);
        }
    }
}
